[testutils] Optimize the runtime of the method verify_no_packet_any for large port sets#231
Conversation
51712d8 to
6735621
Compare
| return True # PASS - packet not observed within timeout window | ||
|
|
||
| for port in ports: | ||
| result = dp_poll( |
There was a problem hiding this comment.
you still validate it port-by-port, and not in parallel unless I don't understand the code
There was a problem hiding this comment.
Correct, the validation is still per port, but the key change is that the timeout is now global, not per-port.
Each port is polled in a non-blocking way into a loop bounded by a single timeout window.
It's not parallel, but it reduces the runtime from O(N × timeout) to O(timeout) and still detects packets on any port. Parallel way is not really possible here because the poll operates on a shared dataplane. Polling it from multiple threads not providing additional benefits and can lead to race conditions.
6735621 to
3d402ef
Compare
|
|
||
|
|
||
| def verify_no_packet_any(test, pkt, ports=[], device_number=0, timeout=None): | ||
| def verify_no_packet_any(test, pkt, ports=[], device_number=0, timeout=1): |
There was a problem hiding this comment.
The default value of timeout was ptf.ptfutils.default_negative_timeout, we should keep it the same.
There was a problem hiding this comment.
Can't be used with default_negative_timeout as before.
Now, it's a global timeout of the method.
Previously, it was the timeout for a single dp_poll call.
This value(0) is too small for the global timeout.
6cd58b1 to
d3d9b5d
Compare
… scale ports number Signed-off-by: AntonHryshchuk <antonh@nvidia.com>
d3d9b5d to
bbb1b6f
Compare
<!--
Please make sure you've read and understood our contributing guidelines:
https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md
** Make sure all your commits include a signature generated with `git commit -s` **
If this is a bug fix, make sure your description includes "fixes #xxxx", or
"closes #xxxx" or "resolves #xxxx"
Please provide the following information:
-->
#### Why I did it
To reduce the runtime of tests
#### How I did it
Created PR for PTF repository, and added a patch to sonic-buildimage
p4lang/ptf#231
#### How to verify it
Run drop_packets tests in sonic-mgmt.
<!--
If PR needs to be backported, then the PR must be tested against the base branch and the earliest backport release branch and provide tested image version on these two branches. For example, if the PR is requested for master, 202211 and 202012, then the requester needs to provide test results on master and 202012.
-->
#### Which release branch to backport (provide reason below if selected)
<!--
- Note we only backport fixes to a release branch, *not* features!
- Please also provide a reason for the backporting below.
- e.g.
- [x] 202006
-->
- [ ] 202305
- [ ] 202311
- [ ] 202405
- [ ] 202411
- [ ] 202505
- [ ] 202511
#### Tested branch (Please provide the tested image version)
<!--
- Please provide tested image version
- e.g.
- [x] 20201231.100
-->
- [ ] <!-- image version 1 -->
- [ ] <!-- image version 2 -->
#### Description for the changelog
<!--
Write a short (one line) summary that describes the changes in this
pull request for inclusion in the changelog:
-->
<!--
Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.
-->
#### Link to config_db schema for YANG module changes
<!--
Provide a link to config_db schema for the table for which YANG model
is defined
Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md
-->
#### A picture of a cute animal (not mandatory but encouraged)
…5583) <!-- Please make sure you've read and understood our contributing guidelines: https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md failure_prs.log skip_prs.log Make sure all your commits include a signature generated with `git commit -s` ** If this is a bug fix, make sure your description includes "fixes #xxxx", or "closes #xxxx" or "resolves #xxxx" Please provide the following information: --> #### Why I did it To reduce the runtime of tests #### How I did it Created PR for PTF repository, and added a patch to sonic-buildimage p4lang/ptf#231 #### How to verify it Run drop_packets tests in sonic-mgmt. <!-- If PR needs to be backported, then the PR must be tested against the base branch and the earliest backport release branch and provide tested image version on these two branches. For example, if the PR is requested for master, 202211 and 202012, then the requester needs to provide test results on master and 202012. --> #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 202305 - [ ] 202311 - [ ] 202405 - [ ] 202411 - [ ] 202505 - [ ] 202511 #### Tested branch (Please provide the tested image version) <!-- - Please provide tested image version - e.g. - [x] 20201231.100 --> - [ ] <!-- image version 1 --> - [ ] <!-- image version 2 --> #### Description for the changelog <!-- Write a short (one line) summary that describes the changes in this pull request for inclusion in the changelog: --> <!-- Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU. --> #### Link to config_db schema for YANG module changes <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md --> #### A picture of a cute animal (not mandatory but encouraged)
Optimize verify_no_packet_any method for large port sets
The original implementation waits for the full timeout on each port
sequentially, resulting in O(N * timeout) runtime (e.g. 500ports → 50 seconds, with 0.1 second of default timeout).
This change introduces a single global timeout and repeatedly polls all ports
using non-blocking dp_poll(timeout=0), ensuring:
Also adds a small sleep to avoid busy looping and reduce CPU usage.